package org.xx.sipahi;

import java.util.Date;
import java.util.Objects;

import static org.xx.armory.commons.SysUtils.copyDate;

/**
 * 公告
 */
public final class Notice
        extends AbstractPage {
    private final boolean star;
    private final Date stickTime;

    public Notice(
            Long id
    ) {
        this(id, "", null, "", "", "", null, "", null, DRAFT, false, null, "");
    }

    public Notice(
            Long id,
            String title,
            Category category,
            String keywords,
            String brief,
            String creator,
            Date createTime,
            String updater,
            Date lastModifiedTime,
            int status,
            boolean star,
            Date stickTime,
            String content
    ) {
        super(id, title, category, keywords, brief, creator, createTime, updater, lastModifiedTime, status, content);

        this.star = star;
        this.stickTime = copyDate(stickTime);
    }

    /**
     * 判断该公告是否需要加上星标提示。
     *
     * @return 该公告是否需要加上星标提示。
     */
    public boolean isStar() {
        return this.star;
    }

    /**
     * 获取置顶时间。
     *
     * @return 置顶时间 。
     */
    public Date getStickTime() {
        return copyDate(this.stickTime);
    }

    @Override
    public final int hashCode() {
        return Objects.hashCode(this.getId());
    }

    @Override
    public final boolean equals(
            Object o
    ) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final Notice other = (Notice) o;
        return Objects.equals(this.getId(), other.getId());
    }

    @Override
    public final String toString() {
        return "Notice(id=" + this.getId() + ",title=" + this.getTitle() + ")";
    }
}
